package com.oocl.aeat.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.oocl.aeat.dao.SysUserDao;
import com.oocl.aeat.pojo.SysUser;
import com.oocl.aeat.util.DBHelper;
import com.oocl.aeat.util.DataSourceUtils;

public class SysUserDaoImpl implements SysUserDao {

	@Override
	public SysUser querySysUserByNameAndPwd(String name, String pwd) {
		Connection conn = DataSourceUtils.getConn();
		SysUser sysUser = null;
		String sql = "select * from sys_user where name = ? and pwd = ? ";
		PreparedStatement pst = null;
		ResultSet rst = null;
		try {
			pst =  conn.prepareStatement(sql);
			pst.setString(1, name);
			pst.setString(2, pwd);
			rst = pst.executeQuery();
		
			while(rst.next()){
				sysUser = new SysUser();
				sysUser.setId(rst.getString(1));
				sysUser.setName(rst.getString(2));
				sysUser.setPwd(rst.getString(3));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(pst, rst, null);
		}
		return sysUser;
	}

}
